Skip to content

Make _observations.py use polars - #14169

Merged
akustn merged 1 commit into
mainfrom
observation-pandas-to-polars
Aug 14, 2026
Merged

Make _observations.py use polars#14169
akustn merged 1 commit into
mainfrom
observation-pandas-to-polars

Conversation

@akustn

@akustn akustn commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Issue
Resolves #my_issue

Approach
Changing from pandas to polars in _observations.py.

(Screenshot of new behavior in GUI if applicable)

  • PR title captures the intent of the changes, and is fitting for release notes.
  • Added appropriate release note label
  • Commit history is consistent and clean, in line with the contribution guidelines.
  • Make sure unit tests pass locally after every commit (git rebase -i main --exec 'just rapid-tests')

When applicable

  • When screenshots are changed: Review screenshot-PR in ert-testdata,
    merge screenshot-PR in ert-testdata before merging this PR.
  • When there are user facing changes: Updated documentation
  • New behavior or changes to existing untested code: Ensured that unit tests are added (See Ground Rules).
  • Large PR: Prepare changes in small commits for more convenient review
  • Bug fix: Add regression test for the bug
  • Bug fix: Add backport label to latest release (format: 'backport release-branch-name')

@akustn akustn self-assigned this Aug 13, 2026
@akustn akustn added this to SCOUT Aug 13, 2026
@akustn akustn added the release-notes:improvement Automatically categorise as improvement in release notes label Aug 13, 2026
@akustn akustn moved this to Ready for Review in SCOUT Aug 13, 2026
@codecov-commenter

codecov-commenter commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.91%. Comparing base (87d7a72) to head (805f0fa).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14169      +/-   ##
==========================================
- Coverage   91.92%   91.91%   -0.02%     
==========================================
  Files         482      482              
  Lines       33498    33498              
==========================================
- Hits        30794    30790       -4     
- Misses       2704     2708       +4     
Flag Coverage Δ
cli-tests 36.47% <7.14%> (-0.02%) ⬇️
fuzz 44.47% <7.14%> (-0.01%) ⬇️
gui-tests 58.84% <7.14%> (-0.01%) ⬇️
performance-and-unit-tests 80.79% <100.00%> (-0.02%) ⬇️
test 45.99% <7.14%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/ert/config/_observations.py 95.54% <100.00%> (ø)

... and 1 file with indirect coverage changes

@codspeed-hq

codspeed-hq Bot commented Aug 13, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 36 untouched benchmarks


Comparing observation-pandas-to-polars (805f0fa) with main (87d7a72)

Open in CodSpeed

@andreas-el

andreas-el commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

I took a look at the observations file in general and noticed that there are a lot repetetive strings that are used.
Would it make sense to extract these as constants to avoid potential typos and such?
Edit: could be part of another PR

@SAKavli SAKavli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty much good to go!
I had some minor comments you can address.

csv_file = pd.read_csv(
filename,
encoding="utf-8",
on_bad_lines="error",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this setting default in polars?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polars throws an error by default when there's malformed rows or parsing failures

Comment thread src/ert/config/_observations.py Outdated
for row in csv_file.itertuples(index=True):
east_val = validate_float(str(row.EAST), "EAST")
north_val = validate_float(str(row.NORTH), "NORTH")
columns = set(csv_file.columns)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set(csv_file.columns)

is called twice, could define this variable name farther up to avoid unnecessary operations

date=str(row.DATE),
name=f"{observation_dict['name']}[{index}]",
well=str(row["WELL_NAME"]),
date=str(row["DATE"]),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you ensure it is tested that a file while doesn't contain the required rows raised an error nicely without traceback?
It is probably tested somewhere already, but nice to make sure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is tests in test_observation_declaration.py covering this. :)
(test_that_missing_user_specified_property_raises_error and test_that_missing_columns_in_rft_observations_file_raises_error)

@ertomatic

Copy link
Copy Markdown
Collaborator

Screenshots differ from baselines. A baseline update PR has been prepared: equinor/ert-testdata#84

@akustn
akustn force-pushed the observation-pandas-to-polars branch from f84fb51 to 9689d6a Compare August 14, 2026 07:04
@ertomatic

Copy link
Copy Markdown
Collaborator

Screenshot tests now pass. The baseline update PR equinor/ert-testdata#84 has been closed.

@akustn
akustn force-pushed the observation-pandas-to-polars branch from 9689d6a to 805f0fa Compare August 14, 2026 12:47
@akustn
akustn merged commit e2cb846 into main Aug 14, 2026
38 checks passed
@akustn
akustn deleted the observation-pandas-to-polars branch August 14, 2026 13:43
@github-project-automation github-project-automation Bot moved this from Reviewed to Done in SCOUT Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes:improvement Automatically categorise as improvement in release notes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants